//
//  LiveNewSignViewModel.m
//  AFNetworking
//
//  Created by tianlong on 2019/8/13.
//

#import "LiveNewSignViewModel.h"
#import "UIView+WXAutoLayout.h"
#import "LiveNewSignView.h"
#import "Masonry.h"

#define Duration 3

@interface LiveNewSignViewModel ()

@end

@implementation LiveNewSignViewModel


- (void)showSignViewWithInterId:(NSString *)interId {
    
    if (self.signView) {
        return;
    }
    
    __weak typeof(self)selfWeak = self;
    
    [self prepareSignView];
    
    //点击签到
    [self.signView setClickedSignButtonBlock:^{
        if (selfWeak.didClickedSignBlock) {
            selfWeak.didClickedSignBlock();
        }
        NSLog(@"新签到：点击了签到按钮");
    }];
    
    //点击关闭
    [self.signView setClickedCloseButtonBlock:^{
        if (selfWeak.didClickedClosedBlock) {
            selfWeak.didClickedClosedBlock();
        }
    }];
    
    //埋点
//    [LiveLogStatisticsHandler liveNewSignLog_startWithWithNonce:[self getNonce] interactiveid:interId];
}



#pragma mark - public function

/** 签到成功 */
- (void)showSignSuccess:(LiveNewSignSuccessEntity *)successEntity myClassStatus:(BOOL)myClassStatus {
    [self prepareSignView];
    [self.signView showSignSuccess];
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(Duration * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        [self removeSignView];
        if (self.signViewWillDismissBlock) {
            self.signViewWillDismissBlock(nil);
        }
    });
    NSLog(@"新签到：签到成功");
}

/** 错过签到 */
- (void)showSignMiss {
    [self prepareSignView];
    [self.signView showSignMiss];
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(Duration * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        [self removeSignView];
    });
    NSLog(@"新签到：错过签到时间");
}

/** 未签到 */
- (void)showSignNot {
    [self prepareSignView];
    [self.signView showSignNot];
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(Duration * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        [self removeSignView];
    });
    NSLog(@"新签到：未签到");
}

- (void)prepareSignView {
    if (!self.signView) {
        LiveNewSignView *signView = [[LiveNewSignView alloc] initWithStuName:self.stuName stuAvatar:self.stuAvatar];
        [self.inView addSubview:signView];
        if (self.inView) {
            [signView mas_makeConstraints:^(MASConstraintMaker *make) {
                make.top.left.bottom.right.offset(0);
            }];
        }
        self.signView = signView;
        self.signView.skinType = self.skinType;
    }
}

@end
